package com.longview.io.modules.app.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.longview.io.common.utils.ImageHeler;
import com.longview.io.common.web.BaseController;
@Controller
@RequestMapping(value = "${frontPath}/appUpload")
public class AppUploadController   extends BaseController{
    @RequestMapping(value = "img", method = {RequestMethod.POST, RequestMethod.GET})
    public @ResponseBody
	String upload(@RequestBody Map<String, Object> params,HttpServletResponse response,HttpServletRequest req) {
    	Map<String,String> returnmap = new HashMap<String,String>();
    	String result;
	    String imageBase64Code = params.get("image").toString();
	    if (ImageHeler.convertCode2Image(imageBase64Code)) {
	        result = "success";
	    } else {
	        result = "failure";
	    }
	    return renderString(response, returnmap);
    }
}
